from django.core.management.base import BaseCommand
from myapp.models import Stock

class Command(BaseCommand):
    help = '初始化股票数据'

    def handle(self, *args, **kwargs):
        stocks_data = [
            {'code': '000001.SZ', 'name': '平安银行'},
            {'code': '600036.SH', 'name': '招商银行'},
            # 添加更多股票...
        ]
        
        for stock_data in stocks_data:
            Stock.objects.get_or_create(
                code=stock_data['code'],
                defaults={'name': stock_data['name']}
            )
        
        self.stdout.write(self.style.SUCCESS('成功初始化股票数据')) 